package com.hh.service.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hh.common.model.user.User;
import com.hh.common.response.UserSpreadPeopleItemResponse;
import com.hh.common.vo.merchant.UserMerIdInfoVo;
import com.hh.common.vo.user.UserAssetVo;
import com.hh.common.vo.user.UserInfoVo;
import com.hh.common.vo.user.UserInvitationCodeInfoVo;
import com.hh.common.vo.wx.UserLoginGetOpenIdVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 用户表 Mapper 接口
 * +----------------------------------------------------------------------
 * | hh [ hh赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2022 https://www.hh.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed hh并不是自由软件，未经许可不能去掉hh相关版权
 * +----------------------------------------------------------------------
 * | Author: hh Team <admin@hh.com>
 * +----------------------------------------------------------------------
 */
public interface UserDao extends BaseMapper<User> {

    List<UserSpreadPeopleItemResponse> getSpreadPeopleList(Map<String, Object> map);

    List<User> findAdminList(Map<String, Object> map);

    UserLoginGetOpenIdVo getByOpenId(String openid);

    @Update("update eb_user set phone = #{phone} where uid = #{uid}")
    void updatePhoneByUid(@Param("uid") Integer uid, @Param("phone") String phone);

    @Select("select mer_id from eb_user where uid = #{id}")
    UserMerIdInfoVo getUserMerIdById(@Param("id") Integer id);

    UserAssetVo getUserAsset(Integer uid);

    @Update("update eb_user set real_name=#{realName},card_id=#{idCard} where uid=#{userId}")
    int updateRealNameStatus(@Param("userId") Integer userId, @Param("realName") String realName, @Param("idCard") String idCard);

    @Select("select uid,mer_id,status,integral,brokerage_price from eb_user where uid = #{userId}")
    UserInfoVo getUserSimpleInfo(@Param("userId") Integer userId);

    @Select("select uid from eb_user where invitation_code = #{invitationCode}")
    UserInvitationCodeInfoVo getUserByInvitationCode(@Param("invitationCode") String invitationCode);

    @Update("update eb_user set now_money=ifnull(now_money, 0)+#{price} where uid = #{uid}")
    int updateAddNowMoney(@Param("uid") Integer uid, @Param("price") BigDecimal price);

    @Update("update eb_user set now_money=ifnull(now_money, 0)-#{price} where uid  = #{uid} and ifnull(now_money, 0) >= #{price}")
    int updateSubtractNowMoney(@Param("uid") Integer uid, @Param("price") BigDecimal price);
}
